package org.dialMsg.Server.ServerImp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.dialMsg.Mapper.ContChildStateMapper;
import org.dialMsg.Pojo.ContChildState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author DPF
 */
@Service
public class GetCrmContactId {
    @Autowired
    private ContChildStateMapper contChildStateMapper;

    public List<Integer> queryIdsByContMobile() {
        QueryWrapper<ContChildState> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("cont_mobile", "111222333444");
        queryWrapper.select("id");
        return contChildStateMapper.selectObjs(queryWrapper).stream()
                .map(obj -> (Integer) obj)
                .collect(Collectors.toList());
    }

    public Integer queryIdByContMobile(Integer dialId) {
        QueryWrapper<ContChildState> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("cont_mobile", "111222333444");
        queryWrapper.eq("dial_result_id", dialId);
        queryWrapper.select("id");
        ContChildState result = contChildStateMapper.selectOne(queryWrapper);
        return result != null ? result.getId() : null;
    }

}
